package tasks.io.core.thread;

import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.Executor;


public abstract class AbstractQueueTask<T> extends AbstractSynTask {

    public AbstractQueueTask(Executor executor) {
        super(executor);
    }


    public boolean add(T t) {
        if (this.isCanceled()) {

            return false;
        }

        return getQueue().add(t);
    }

    public abstract ConcurrentLinkedQueue<T> getQueue();

    /**
     * 清空处理的队列消息
     */
    public void clearQueue() {
        if (getQueue() != null) {
            getQueue().clear();
        }
    }

    @Override
    public boolean isNeededExecute() {
        return (getQueue() != null && !getQueue().isEmpty()) && !this.isCanceled();
    }


}
